package org.example.Window;

import org.example.player.Player;
import org.example.treasure.Treasure;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MessageDialog extends JDialog {
    public static MainWindow owner;
    ImageIcon CGImage;
    Point center;

    /**
     *  通关的弹窗
     * @param life
     * @param money
     */
    public MessageDialog(int life,int money) {
        super(owner,"游戏提示",true);
        getContentPane().setLayout(null);
        center = owner.getLocation();
        this.setBounds(center.x + 300, center.y + 200, 550,440);
        this.setResizable(false);
        this.setUndecorated(true);


        //添加图片
        CGImage = new ImageIcon("src/images/过关CG.png");
        JLabel imageLabel = new JLabel(CGImage);
        imageLabel.setBounds(10, 10,540,300);
        imageLabel.setOpaque(false);
        this.getContentPane().add(imageLabel);

        //提示消息
        JLabel textLabel = new JLabel("血量："+life+"   经济："+money);
        Font font = new Font(null,Font.BOLD,25);
        textLabel.setFont(font);
        textLabel.setBounds(13,330,300,50);
        this.getContentPane().add(textLabel);

        //添加回到主菜单的按钮
        JButton back = new JButton(new ImageIcon("src/images/返回主菜单.png"));
        back.setBounds(300,335,230,40);
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                owner.clearAll();
                owner.initView();
                if (!owner.treasures.isEmpty()){
                    owner.treasures.clear();
                }
                dispose();

            }
        });
        this.getContentPane().add(back);

        //添加行进路线
        String route ="路线：皮斯佛";
        for (Treasure treasure : Player.route) {
            route += " => " +treasure.name ;
        }

        JLabel label = new JLabel("<html>"+ route +"</html>");
        label.setBounds(20, 380,530,50);
        this.getContentPane().add(label);

        //添加背景效果
        JLabel background = new JLabel(new ImageIcon("src/images/提示版背景.png"));
        background.setBounds(0, 0,550,440);
        background.setOpaque(false);
        this.getContentPane().add(background);
    }

    /**
     * 未通关的弹窗
     * @param money
     */
    public MessageDialog(int money)  {
        super(owner,"游戏提示",true);
        setLocationRelativeTo(null);//居中
        getContentPane().setLayout(null);
        center = owner.getLocation();
        this.setBounds(center.x + 300, center.y + 200, 550,440);
        this.setResizable(false);
        this.setUndecorated(true);


        //添加图片
        CGImage = new ImageIcon("src/images/战败CG.png");
        JLabel imageLabel = new JLabel(CGImage);
        imageLabel.setBounds(10, 10,540,300);
        imageLabel.setOpaque(false);
        this.getContentPane().add(imageLabel);

        //提示消息
        JLabel textLabel = new JLabel("经济："+money);
        Font font = new Font(null,Font.BOLD,25);
        textLabel.setFont(font);
        textLabel.setBounds(13,330,300,50);
        this.getContentPane().add(textLabel);

        //添加回到主菜单的按钮
        JButton back = new JButton(new ImageIcon("src/images/返回主菜单.png"));
        back.setBounds(300,335,230,40);
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                owner.clearAll();
                owner.initView();
                if (!owner.treasures.isEmpty()){
                    owner.treasures.clear();
                }
                dispose();

            }
        });
        this.getContentPane().add(back);

        //添加行进路线
        String route ="路线：皮斯佛";
        for (Treasure treasure : Player.route) {
            route += " => " +treasure.name ;
        }

        JLabel label = new JLabel("<html>"+ route +"</html>");
        label.setBounds(20, 385,530,50);
        this.getContentPane().add(label);

        //添加背景效果
        JLabel background = new JLabel(new ImageIcon("src/images/提示版背景.png"));
        background.setBounds(0, 0,550,440);
        background.setOpaque(false);
        this.getContentPane().add(background);
    }
}
